package com.koron.order.defectPending.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.common.util.CheckPermission;
import com.koron.order.defectPending.bean.po.DefectPendingPo;
import com.koron.order.defectPending.bean.query.DefectPendingQuery;
import com.koron.order.defectPending.service.DefectPendingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 缺陷工单下缺陷待处理信息从表(DefectPending)表控制层
 *
 * @author zhouj
 * @since 2022-02-09 10:36:19
 */
@Api(tags = "缺陷工单下缺陷待处理信息从表(DefectPending)")
@RestController
@RequestMapping("/defectPending/")
public class DefectPendingController {

    @Autowired
    private DefectPendingService defectPendingService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改缺陷工单下缺陷待处理信息从表")
    @PostMapping("insertOrUpdate")
    public Response<DefectPendingPo> insertOrUpdate(@RequestBody DefectPendingPo defectPending) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), defectPendingService, "insertOrUpdate", DefectPendingPo.class, defectPending));
    }

    @ApiOperation(value = "新增缺陷工单下缺陷待处理信息从表")
    @PostMapping("insert")
    public Response<Integer> insert(@RequestBody DefectPendingPo defectPending) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), defectPendingService, "insert", Integer.class, defectPending));
    }

    @ApiOperation(value = "批量新增缺陷工单下缺陷待处理信息从表")
    @PostMapping("insertBatch")
    public Response<Integer> insertBatch(@RequestBody List<DefectPendingPo> defectPendingList) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), defectPendingService, "insertBatch", Integer.class, defectPendingList));
    }

    @ApiOperation(value = "根据id更新缺陷工单下缺陷待处理信息从表")
    @PutMapping("update")
    public Response<Integer> update(@RequestBody DefectPendingPo defectPending) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), defectPendingService, "update", Integer.class, defectPending));
    }

    @ApiOperation(value = "根据id删除缺陷工单下缺陷待处理信息从表")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), defectPendingService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询缺陷工单下缺陷待处理信息从表")
    @CheckPermission
    @GetMapping("queryById")
    public Response<DefectPendingPo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), defectPendingService, "queryById", DefectPendingPo.class, id));
    }

    @ApiOperation(value = "不分页查询缺陷工单下缺陷待处理信息从表列表")
    @GetMapping("queryList")
    public Response<List> queryList(DefectPendingQuery defectPendingQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), defectPendingService, "queryList", List.class, defectPendingQuery));
    }

    @ApiOperation(value = "分页查询缺陷工单下缺陷待处理信息从表列表")
    @GetMapping("queryVoPageList")
    public Response<PageInfo> queryVoPageList(DefectPendingQuery pendingQuery, PageQuery pageQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), defectPendingService, "queryVoPageList", PageInfo.class, pendingQuery, pageQuery));
    }

}
